<?php
require_once 'PHPUnit/Framework.php';
require_once(dirname(__FILE__).'/../../../config/UCConfMacro.php'); 
require_once(dirname(__FILE__).'/../../../models/relation/UCModRelation.php');
require_once(dirname(__FILE__).'/../../../libraries/UCLibLogger.php');  
/**
@assert (...) == X    assertEquals(X, method(...))
@assert (...) != X    assertNotEquals(X, method(...))
@assert (...) === X    assertSame(X, method(...))
@assert (...) !== X    assertNotSame(X, method(...))
@assert (...) > X    assertGreaterThan(X, method(...))
@assert (...) >= X    assertGreaterThanOrEqual(X, method(...))
@assert (...) < X    assertLessThan(X, method(...))
@assert (...) <= X    assertLessThanOrEqual(X, method(...))
@assert (...) throws X    @expectedException X
*/
class UCModRelationTest extends PHPUnit_Framework_TestCase {
    private $_rmod;
    private $_gid;
    
    protected function setUp()
    {
        UCLibLogger::attach(new StdoutLogOb());
        UCLibLogger::setMask(UCLIB_LOG_PRI_ALL^UCLIB_LOG_PRI_RPC_DEBUG);
        $this->_rmod = new UCModRelation(110000308490);
        $ret= $this->_rmod->addRelation(1234);
        

    }
    
    protected function tearDown()
    {
        $this->_rmod->deleteRelation(1234);
        
    }
    
    /**
    * @dataProvider providerUserid
    * 
    */
    function test_addRelation($uid)
    {
        $ret = $this->_rmod->addRelation($uid);
        $this->assertTrue($ret, 'errno['.$this->_rmod->getLastErrno().'],error:'.$this->_rmod->getLastError());
        $this->_rmod->deleteRelation($uid);
    }
    
    function test_getFollowsDistinct()
    {
        $ret = $this->_rmod->getFollowsDistinct();
        $this->assertGreaterThan(0, $ret['totalResults'], 'error code:'.$this->_rmod->getLastErrno());
    }
    
    function test_getBiRelation()
    {
        $ret = $this->_rmod->getBiRelation();
        $this->assertGreaterThan(-1, $ret['totalResults'], 'error code:'.$this->_rmod->getLastErrno());
    }
    
    function test_getRelationFollow()
    {
        $ret = $this->_rmod->getRelationFollow();
        $this->assertGreaterThan(0, $ret['totalResults'], 'error code:'.$this->_rmod->getLastErrno());
    }
    
    function test_getPersonGroups()
    {
        $ret = $this->_rmod->getPersonGroups();
        //var_dump($ret);
        $this->assertGreaterThan(0, $ret['totalResults'], 'error code:'.$this->_rmod->getLastErrno());
    }
    
    
    function test_getRelationType()
    {
        $ret = $this->_rmod->getRelationType(array(1234), 1);
        $this->assertEquals($ret[1234], 1, 'error code:'.$this->_rmod->getLastErrno());
        
        $ret = $this->_rmod->getRelationType(array(114444), 1);
        $this->assertEquals($ret[114444], 0, 'error code:'.$this->_rmod->getLastErrno());
    }
    
    function test_getSingleRelationType()
    {
        $ret = $this->_rmod->getSingleRelationType(1234, 1);
        $this->assertEquals($ret, 1, 'error code:'.$this->_rmod->getLastErrno());
        
        $ret = $this->_rmod->getSingleRelationType(114444, 1);
        $this->assertEquals($ret, 0, 'error code:'.$this->_rmod->getLastErrno());
    }
    
    function test_addGroup()
    {
        $ret = $this->_rmod->addGroup('ff10');
        $this->assertGreaterThan(0, $ret, 'error code:'.$this->_rmod->getLastErrno(), 'error code:'.$this->_rmod->getLastErrno());    
        // $ret['data']
        $ret = $this->_rmod->deleteGroup($ret);
        $this->assertTrue($ret, 'error code:'.$this->_rmod->getLastErrno(), 'error code:'.$this->_rmod->getLastErrno());    
    }
    
    function test_updateGroupName()
    {
        $gid = $this->_rmod->addGroup('fffff');   
        $ret = $this->_rmod->updateGroupName($gid, 'new name');
        $this->assertTrue($ret, 'error code:'.$this->_rmod->getLastErrno()); 
        $ret = $this->_rmod->getGroup($gid);
        $this->_rmod->deleteGroup($gid);
    }
    
    function test_getRelationReverse()
    {
        $ret = $this->_rmod->getRelationReverse();
        $this->assertGreaterThan(0, $ret['totalResults'], 'error code:'.$this->_rmod->getLastErrno());
    }
    
    function test_getRelationFollowCount()
    {
        $ret = $this->_rmod->getRelationFollowCount();
        $this->assertGreaterThan(0, $ret, 'error code:'.$this->_rmod->getLastErrno(), 'error code:'.$this->_rmod->getLastErrno());    
    }
    
    function test_getRelationReverseCount()
    {
        $ret = $this->_rmod->getRelationReverseCount();
        $this->assertGreaterThan(0, $ret, 'error code:'.$this->_rmod->getLastErrno(), 'error code:'.$this->_rmod->getLastErrno());    
    }
    
    function test_getBiRelationCount()
    {
        $ret = $this->_rmod->getRelationReverseCount();
        $this->assertGreaterThan(0, $ret, 'error code:'.$this->_rmod->getLastErrno(), 'error code:'.$this->_rmod->getLastErrno());    
    }
    
    /**
    * @dataProvider providerUserid 
    */
    function test_updateRelationGroupIdByBatch($uid)
    {
        $ret = $this->_rmod->addRelation($uid);
        //$this->assertTrue($ret);
        var_dump($uid);
        $ret = $this->_rmod->updateRelationGroupIdByBatch($uid, array(3,4));
        //echo 'errno['.$this->_rmod->getLastErrno().'],error:'.$this->_rmod->getLastError();
        $this->assertTrue($ret, 'errno['.$this->_rmod->getLastErrno().'],error:'.$this->_rmod->getLastError());
        $ret = $this->_rmod->deleteRelation($uid);
        $this->assertTrue($ret);
    }
    
    function test_getFansNumberByBatch()
    {
        $ids = array(8061282,8061290);
        $ret = $this->_rmod->getFansNumberByBatch($ids);
        var_dump($ret);
        echo 'errno['.$this->_rmod->getLastErrno().'],error:'.$this->_rmod->getLastError()."\n";
    }
                                            
    
    
    function providerUserid()
    {
        return array(
            array(11234),
        );
    }
    
}


?>